package com.hspedu.jdbc;

import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/4/7
 * @time 16:27
 * 第一个JDBC程序
 */
public class JDBC01 {
    public static void main(String[] args) throws SQLException {

        //1. 注册驱动
        Driver driver = new Driver();
        //2. 得到连接
        String url = "jdbc:mysql://localhost:3306/classtest";
        Properties properties = new Properties();
        properties.setProperty("user", "root");
        properties.setProperty("password", "GUQIhao123.");
        Connection connect = driver.connect(url, properties);
        //3. 执行sql
        String sql = "insert into actor values(null, '刘德华','男','1970-11-11','110')";
        Statement statement = connect.createStatement();
        int affectRows = statement.executeUpdate(sql);
        if (affectRows > 0) {
            System.out.println("sql执行成功");
        } else {
            System.out.println("sql执行失败");
        }
        //4. 关闭资源
        statement.close();
        connect.close();
    }
}
